import { defaultColors } from '@/components/common/VisualizationComp/constants'
import ChartProtoConfig from '@/components/common/VisualizationComp/proto-config'
import { getDefaultValueFromProto } from '@/components/common/VisualizationComp/ChartConfig/common'
import { parseSettingToChartOption } from '@/components/common/VisualizationDashboard/util'
import { defaultOptions as wordCloudDefaultOptions } from '@/components/common/VisualizationComp/ChartConfig/wordcloud-config'

/**
 * 各chart默认配置
 * 主要用于一些特殊chart的特殊配置，
 * 比如词云组件不需要x/y 轴的配置，需要词的文本样式配置等
 */
const chartDefaultOptions: any = {
  wordCloud: wordCloudDefaultOptions,
}

/**
 * 详细版本的默认配置，默认主要素都展示齐全
 */
export const detailDefaultOptions = {
  title: '',
  titleIsShow: true,
  xAxisIsShow: true,
  yAxisIsShow: true,
  axisGridIsShow: true,
  xAxisGridIsShow: true,
  yAxisGridIsShow: true,
  visibleItemsNumber: 16,
  tooltipIsShow: true,
  colors: defaultColors,
  xAxisGridStyle: 'null',
  yAxisGridStyle: 'null',
  xAxisTickIsShow: false,
  yAxisTickIsShow: false,
  xAxisTitleIsShow: true,
  xAxisTitle: '',
  yAxisTitleIsShow: true,
  yAxisTitle: '',
  legendPosition: 'right',
  labelIsShow: false,
  maxBarWidth: 28,
  // axisLayout: 'horizontal',
  // axisScaleType: 'linear',
  // lineSmooth: false,
}

/**
 * 简版图表的默认配置，适用于小区域展示
 * 无坐标轴标题、无网格线展示等
 */
export const simpleCommonDefultOptions = {
  titleIsShow: true,
  xAxisIsShow: false,
  yAxisIsShow: false,
  axisGridIsShow: false,
  xAxisGridIsShow: false,
  yAxisGridIsShow: false,
  visibleItemsNumber: 16,
}

/*
 * 根据chartType获取默认配置
 */
export const getDetailDefaultOptionsByChartType = (
  chartType: string | Array<string>
) => {
  const chartTypeString = Array.isArray(chartType) ? chartType[1] : chartType // 兼容性获取chartType

  let options = chartDefaultOptions[chartTypeString]
    ? chartDefaultOptions[chartTypeString]
    : { ...detailDefaultOptions }
  if (ChartProtoConfig[chartTypeString]) {
    options = {
      ...options,
      ...getDefaultValueFromProto(ChartProtoConfig[chartTypeString]),
    }
  }
  return parseSettingToChartOption(options)
}
